﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.SafetyObjects.CCoSafetyBreachModeCmd
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using Microsoft.Win32;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.SafetyObjects;

public class CCoSafetyBreachModeCmd : TxToggleButtonCommand
{
  internal static string REGPATH = "HKEY_CURRENT_USER\\Software\\TECNOMATIX\\TUNE\\GeneralSettings";
  internal static string IS_SAFETY_BREACH_ON_STR = "IsSafetyBreachOn";
  public static bool Toggled;

  public CCoSafetyBreachModeCmd() => this.LoadState();

  public virtual bool Push => CCoSafetyBreachModeCmd.Toggled;

  public virtual string Category => StringTable.SAFETY_CATEGORY;

  public virtual string Name => StringTable.SAFETY_MODE_NAME;

  public virtual string Description => StringTable.SAFETY_MODE_DESCRIPTION;

  public virtual string Tooltip => StringTable.SAFETY_MODE_TOOLTIP;

  public virtual string LargeBitmap
  {
    get => "SafetyObjects.Resources.cmdActivateSafetyBreachSimulation32.png";
  }

  public virtual string MediumBitmap
  {
    get => "SafetyObjects.Resources.cmdActivateSafetyBreachSimulation24.png";
  }

  public virtual string Bitmap => "SafetyObjects.Resources.cmdActivateSafetyBreachSimulation16.bmp";

  public virtual ITxImage Image
  {
    get => (ITxImage) TxImageManager.GetImageByKey("ActivateBreachSimulation");
  }

  public virtual ITxCommandEnabler CommandEnabler { get; } = (ITxCommandEnabler) new CCoSafetyBreachModeCmdEnabler();

  public virtual void Execute(object cmdParams)
  {
    CCoSafetyBreachModeCmd.Toggled = !CCoSafetyBreachModeCmd.Toggled;
    this.SaveState();
  }

  private void LoadState()
  {
    string str = Registry.GetValue(CCoSafetyBreachModeCmd.REGPATH, CCoSafetyBreachModeCmd.IS_SAFETY_BREACH_ON_STR, (object) null) as string;
    if (!string.IsNullOrEmpty(str))
    {
      CCoSafetyBreachModeCmd.Toggled = str == "True";
    }
    else
    {
      CCoSafetyBreachModeCmd.Toggled = true;
      this.SaveState();
    }
  }

  private void SaveState()
  {
    string str = CCoSafetyBreachModeCmd.Toggled.ToString();
    Registry.SetValue(CCoSafetyBreachModeCmd.REGPATH, CCoSafetyBreachModeCmd.IS_SAFETY_BREACH_ON_STR, (object) str);
  }
}
